package com.ycb.controller;

import com.ycb.entity.User;
import com.ycb.feign.UserClient;
import com.ycb.service.UserService;
import io.seata.core.context.RootContext;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黄泽群
 * @since 2023-12-11
 */
@Slf4j
@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class UserController implements UserClient {

    private final UserService userService;

    @Override
    public User subAmount(Integer userId, Integer subAmt) {
        BusinessActionContext context = BusinessActionContextUtil.getContext();
        log.warn(" UserController >> subAmount :{} userId:{} subAmt:{} inGlobalTransaction:{}",context,userId,subAmt, RootContext.inGlobalTransaction());
        return userService.subAmount(context,userId,subAmt);
    }
}
